Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console_linux: Fix race: lock Cond before Signal. #27

Merged
merged 1 commit into from
Jul 5, 2018
Merged

console_linux: Fix race: lock Cond before Signal. #27

merged 1 commit into from
Jul 5, 2018

Conversation

gerasiov
Copy link
Contributor

@gerasiov gerasiov commented Jul 3, 2018

Possible race:


Thread1:			Thread2:
line 178: Read() -> EAGAIN	...
<reschedule>			line 110: EpollWait()
...				line 124: signalRead()
...				...
line 191: Wait()		...
				line 110: EpollWait()

Thread2 (epoll) sends signalRead() (via sync.Cond) but Thread1 is not waiting
yet. Then is start to wait, but no more signals will arrive (because Thread2
is sleeping in EpollWait() on edge-triggered epoll.

To prevent this race one should held Lock when sending signalRead().

The same situation goes with Write loop.

Bug was reported to docker: docker/for-linux#353

Signed-off-by: Alexander Gerasiov gerasiov@yandex-team.ru

@gerasiov
Copy link
Contributor Author

gerasiov commented Jul 3, 2018

It looks, like your travis install/config has some problems.

@crosbymichael
Copy link
Member

Thanks, looking into the travis issue

@crosbymichael
Copy link
Member

@gerasiov could you rebase this on master? We merge a travis fix for the failing CI.

Possible race:

Thread1:			Thread2:
line 178: Read() -> EAGAIN	...
<reschedule>			line 110: EpollWait()
...				line 124: signalRead()
...				...
line 191: Wait()		...
				line 110: EpollWait()

Thread2 (epoll) sends signalRead() (via sync.Cond) but Thread1 is not waiting
yet. Then it starts to wait, but no more signals will arrive (because Thread2
is sleeping in EpollWait() on edge-triggered epoll.

To prevent this race one should held Lock when sending signalRead().

The same situation goes with Write loop.

Bug was reported to docker: docker/for-linux#353

Signed-off-by: Alexander Gerasiov <gerasiov@yandex-team.ru>
@crosbymichael
Copy link
Member

LGTM

Copy link
Contributor

@mlaventure mlaventure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ec.readc.Signal()
ec.readc.L.Unlock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit.. maybe use defer for the Unlock() calls to mirror existing code pattern.

@djmitche
Copy link

Is there a way to track when this would make it into a Docker release?

@mlaventure
Copy link
Contributor

@djmitche it looks like 18.06 has the fix: moby/moby#35865 (comment)

petrosagg added a commit to balena-os/balena-engine that referenced this pull request Sep 21, 2018
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
Connects-To: moby/moby#35865
Connects-To: containerd/console#27
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Mar 28, 2019
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Mar 28, 2019
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 12, 2019
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 12, 2019
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 12, 2019
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 25, 2019
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Jul 14, 2019
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Aug 26, 2019
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Sep 5, 2019
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Dec 31, 2019
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
adrianreber pushed a commit to adrianreber/runc that referenced this pull request Feb 10, 2020
relevant changes:

- containerd/console#27 console_linux: Fix race: lock Cond before Signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants